package com.small.site.controller;

import com.small.site.base.ITestService;
import com.small.site.pojo.Test;
import com.small.site.util.R;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author xiaochi
 * @date 2021/11/21 15:30
 * @desc TestController
 */
@RestController
@RequestMapping("/manager")
public class TestController{

    @DubboReference(check = false)
    private ITestService testService;

    @GetMapping("/test")
    public R<List<Test>> test(){
        return R.ok(testService.findAll());
    }

    @GetMapping("/test/find")
    public R<List<Test>> findWhere(){
        return R.ok(testService.findAndWhere(Test.builder().build()));
    }

    @GetMapping("/test/add")
    public R<String> create(){
        int res = testService.insert(Test.builder().name("小二manager" + Math.random() * 1000).build());
        if (res==1) {
            return R.ok();
        }
        return R.error();
    }
}
